package com.example.elderlycaresystem.mapper;


import com.example.elderlycaresystem.entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("INSERT INTO users (user_name, password, email, phone_number, address) " +
            "VALUES (#{userName}, #{password}, #{email}, #{phoneNumber}, #{address})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);

    @Select("SELECT * FROM users WHERE id = #{id}")
    User selectUserById(Long id);

    @Select("SELECT * FROM users WHERE user_name = #{userName}")
    User selectUserByUserName(String userName);

    @Select("SELECT * FROM users")
    List<User> selectAllUsers();

    @Update("UPDATE users SET user_name=#{userName}, password=#{password}, email=#{email}, " +
            "phone_number=#{phoneNumber}, address=#{address} WHERE id=#{id}")
    int updateUser(User user);

    @Delete("DELETE FROM users WHERE id = #{id}")
    int deleteUserById(Long id);

    @Select("SELECT * FROM users WHERE email = #{email}")
    User selectUserByEmail(String email);
    @Select("SELECT * FROM users WHERE user_name = #{userName} AND password = #{password}")
    User selectUserByUserNameAndPassword(String username, String password);
}